package com.adinnet.admin.information.service.impl;

import com.adinnet.admin.information.model.Information;
import com.adinnet.admin.information.mapper.InformationMapper;
import com.adinnet.admin.information.model.vo.InformationReq;
import com.adinnet.admin.information.service.InformationService;
import com.adinnet.common.utils.StringUtil;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 资讯管理 服务实现类
 * </p>
 *
 * @author chenjia
 * @since 2020-12-17
 */
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, Information> implements InformationService {

    @Override
    public PageResult<Information> List(InformationReq req) {
        Page<Information> iPage = new Page<>(req.getPage(), req.getLimit());
        QueryWrapper<Information> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",0);
        if(!StringUtil.isBlank(req.getInformationName())){
            queryWrapper.like("information_name",req.getInformationName());
        }
        queryWrapper.orderByDesc("updated_date");
        IPage page = baseMapper.selectPage(iPage, queryWrapper);
        return new PageResult<Information>(page.getRecords(),page.getTotal());
    }

    @Override
    public JsonResult deleteIds(String informationIds) {
        baseMapper.deleteIds(informationIds);
        return JsonResult.ok("操作成功");
    }
}
